import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)

function getMobileHomeEntryList () {
  let jsonData = sessionStorage.getItem('mobileHomeEntryList');
  try {
    jsonData = JSON.parse(jsonData);
  } catch (e) {
    jsonData = [];
  }

  return jsonData;
}

export default new Vuex.Store({
  state: {
    mobileHomeEntryList: getMobileHomeEntryList()
  },
  mutations: {
    setHomeEntryList (state, data) {
      let tempList = [];
      if (Array.isArray(data) && data.length > 0) {
        tempList = data;
      }
      let jsonData = JSON.stringify(tempList);
      sessionStorage.setItem('mobileHomeEntryList', jsonData);
      state.mobileHomeEntryList = tempList;
    }
  },
  getters: {
    getHomeEntryList (state) {
      return state.mobileHomeEntryList;
    }
  }
})
